﻿using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text;
using SaiLing.Domain.Specification;
using SaiLing.SingleSignOn.Domain.Entities.System;

namespace SaiLing.SingleSignOn.Domain.Specifications.System
{
    public class ModuleSpecification : ISpecification<Module>
    {
        private string Name { get; set; }
        private Guid Appid { get; set; }

        public ModuleSpecification(string name,Guid? appid)
        {
            Name = name;
            Appid = appid==null?Guid.Empty:appid.Value; 
        }

        public Expression<Func<Module, bool>> SatisfiedBy()
        {
            Specification<Module> spec = new TrueSpecification<Module>();
            spec &= new DirectSpecification<Module>(x => !x.LogicRemove);
            if (!string.IsNullOrWhiteSpace(Name))
                spec &= new DirectSpecification<Module>(x => x.Name.Contains(Name));
            if (Appid!=null && Appid!=Guid.Empty)
                spec &= new DirectSpecification<Module>(x => x.AppId==Appid);
            return spec.SatisfiedBy();
        }
    }
}
